<?php

class LittleTools {

    //反解enurl过的链接
    public static function decodeUrl($url) {
        return urldecode($url);
    }

    //反加htmlspecialchars过的HTML代码内容。
    public static function decodeHtml($htmlContent) {
        return htmlspecialchars_decode($htmlContent);
    }

    //过滤windows下非法的文件命名字符
    public static function filterWindowsFileNameChar($fileName) {
        $specailChars   = array("/" => "",
            "/" => '',
            "|" => '',
            "*" => '',
            "?" => '',
            ":" => '',
            "<" => '',
            ">" => '',
            "\"" => '',
            "\\" => '',);
        return strtr($fileName, $specailChars);
    }

    //过滤HTML标签
    public static function filterHtmlTag($content, $replace = '') {
        $mode   = '%<\/?[:\w]+(\s?[:\w]+(:\w+)?="([/\w.:;\-()\s#]|[\x{4E00}-\x{9FFF}])*"\s?)*>%simxu';

        return preg_replace($mode, $replace, $content);
    }

    //换HTML的换行标记为\n
    public static function replaceRowTagToN($content, $replace = "\n") {
        return preg_replace('%<(\/(td|p|div|h\d{1,4}|li|dd)|br\s?\/)>%simx', $replace, $content);
    }

    //过滤所有的空格
    public static function filterSpace($content, $replace = '') {
        return preg_replace('%\s+%simx', $replace, $content);
    }

    //得到文件的类型[需要.]
    public static function getFileType($fileName) {
        return substr($fileName, strrpos($fileName, '.'));
    }

    //HTML的正常转码
    public static function htmlDecode($content) {
        return urldecode($content);
    }
    
    //格式化模板文件名
    public static function formatIeTempFileName($fileName) {
        return preg_replace('/\[\d+\]/i', '', self::htmlDecode($fileName));
    }

}

?>
